package com.cgnpc.scp.achievement.controller;

import cn.com.cgnpc.aep.bizcenter.appcenter.sdk.result.ApiResult;
import com.cgnpc.cud.annotation.OperatorType;
import com.cgnpc.cud.annotation.UBA;
import com.cgnpc.cud.core.domain.AjaxResult;
import com.cgnpc.scp.achievement.mybatis.entity.PaperApply;
import com.cgnpc.scp.achievement.pojo.IdReq;
import com.cgnpc.scp.achievement.service.PaperService;
import com.cgnpc.scp.common.bean.CreateFileInfo;
import com.cgnpc.scp.common.bean.MyPageResult;
import com.cgnpc.scp.common.utils.AjaxResultUtil;
import com.cgnpc.scp.run.mybatis.entity.MarketInfo;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.MessageSource;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.awt.print.Paper;
import java.util.Map;

/**********************************
 * 用途说明: 论文管理
 * 作者姓名: zhangyibing
 * 创建时间: 2020年9月26日23:47:17
 ***********************************/
@RestController
@RequestMapping("/scp/achievement/paper")
public class PaperController {
    private static final Logger LOGGER = LoggerFactory.getLogger(PaperController.class);

    @Autowired
    private MessageSource messageSource;

    @Autowired
    private PaperService paperService;

    /**********************************
     * 用途说明: 调试科研创新管理 - 论文新增(发起流程或存草稿)
     * 参数说明 params
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="调试科研创新管理 - 论文新增")
    @UBA(module = "成果管理", action = "论文新增", channel = OperatorType.Button)
    @PostMapping("/savePaper")
    public AjaxResult savePaper(@RequestBody Map<String, Object> params) {
        try {
            return paperService.savePaper(params);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 提交/回退流程
     * 参数说明 params
     * 返回值说明:
     ***********************************/
    @PostMapping("/submitProcess")
    @UBA(module = "论文管理", action = "论文审批流程提交/回退", channel = OperatorType.Button)
    @ApiOperation(value="提交/回退流程")
    public AjaxResult submitProcess(HttpServletRequest request,@RequestBody Map<String, Object> params) {
        try {
            ApiResult apiResult = paperService.submitProcess(params);
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,apiResult);
        } catch (Exception e) {
            LOGGER.error("paperController submitProcess error : {}",e.getMessage(),e);
            return AjaxResultUtil.createI18nDefaultError(request,messageSource,e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 调试科研创新管理 - 发起变更（此接口暂时作废）
     * 参数说明 params
     * 返回值说明:
     ***********************************/
    /**@ApiOperation(value="调试科研创新管理 - 发起变更（此接口暂时作废）")
    @PostMapping("/updatePaper")
    public AjaxResult updatePaper(@RequestBody Map<String, Object> params) {
        try {
            return paperService.updatePaper(params);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }
    }**/

    /**********************************
     * 用途说明: 调试科研创新管理 - 论文查看
     * 参数说明 params
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="调试科研创新管理 - 论文查看")
    @UBA(module = "成果管理", action = "论文查看", channel = OperatorType.Button)
    @PostMapping("/info")
    public AjaxResult info(@RequestBody IdReq idReq) {
        try {
            return paperService.info(idReq.getId());
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }
    }

    /**********************************
     * 用途说明: 调试科研创新管理 - 论文列表
     * 参数说明 params
     * 返回值说明: 论文列表
     ***********************************/
    @ApiOperation(value="调试科研创新管理 - 论文列表")
    @UBA(module = "成果管理", action = "论文列表", channel = OperatorType.Page)
    @RequestMapping(value = "/listPage", method = {RequestMethod.POST})
    public AjaxResult listPage(HttpServletRequest request, @RequestBody Map<String, Object> params) {
        MyPageResult<PaperApply> result = paperService.queryPaperApplyPageList(params);
        return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,result);
    }

    /**********************************
     * 用途说明: 调试科研创新管理 - 论文管理-导出Excel
     * 参数说明: HttpServletRequest request, @RequestBody T reqEntity
     * 返回值说明: Object
     ***********************************/
    @ApiOperation(value = "调试经营管理-论文管理-导出Excel")
    @UBA(module = "成果管理", action = "论文管理-导出Excel", channel = OperatorType.Button)
    @RequestMapping(value = "/exportExcel", method = {RequestMethod.POST})
    @ResponseBody
    public Object exportExcel(HttpServletRequest request, @RequestBody Map<String, Object> params) {
        AjaxResult ajaxResult = null;
        try {
            CreateFileInfo createFileInfo = paperService.exportExcel(params);
            ajaxResult = AjaxResultUtil.createSuccessMessage(createFileInfo);
        } catch (Exception e) {
            LOGGER.error("exportExcel.error;", e);
            ajaxResult = AjaxResultUtil.createErrorMessage();
        }
        return ajaxResult;
    }

    /**********************************
     * 用途说明: 调试科研创新管理 - 论文删除草稿
     * 参数说明 params
     * 返回值说明:
     ***********************************/
    @ApiOperation(value="调试科研创新管理 - 论文删除草稿")
    @UBA(module = "成果管理", action = "论文删除草稿", channel = OperatorType.Page)
    @RequestMapping(value = "/deleteDraft", method = {RequestMethod.POST})
    public AjaxResult deleteDraft(HttpServletRequest request, @RequestBody Map<String, Object> params) throws Exception {
        try {
            ApiResult result = paperService.deleteDraft(params);
            return AjaxResultUtil.createI18nDefaultSuccess(request,messageSource,result);
        } catch (Exception e) {
            LOGGER.error("exportExcel.error;", e);
            return AjaxResultUtil.createErrorMessage();
        }
    }

}
